package Symulator2009;

import java.awt.Color;
import java.awt.Graphics;

class Car{
	private boolean isVisible;
	private int x;
	private int y;
	private boolean isFirst;
	private int acceleration;
	private double speed;
	private double droga;
	private boolean isHorizontal;
	private Lights l;
	private int type;
	private int currentLight;
	private int lights;
	Car(Lights l, int type){
	this.type=type;
	this.l=l;
	this.acceleration=-1;
	this.isVisible=true;
	this.isHorizontal=true;
	this.x=5;
	this.y=168;
	this.currentLight=1;
	this.lights=3;
	this.droga=0;
	}
	public void update(Graphics g){
	long t=System.currentTimeMillis();
	changeDirection(t);
	if(isVisible)
	drawCar(g);
	}
	private void drawCar(Graphics g){
	//g.draw3DRect(100, 100, 16, 6, true);
	Color c=g.getColor();
	if(acceleration==-1)
	g.setColor(Color.red);
	else if(acceleration==0)
	g.setColor(Color.yellow);
	else
	g.setColor(Color.green);
	if(isVisible)
	g.fill3DRect(x, y, 16, 8, true);
	g.setColor(c);
	}
	private void changeDirection(long t){
//if(x>l.getLights()[currentLight].getWhereStopX())
		if(x>l.getLight(currentLight).getstopXa())
			if(currentLight!=lights)
				currentLight++;
			else if(x>530)
				isVisible=false;
	
//if(l.getLights()[currentLight].getWhereStopX()>x&&x+16<l.getLights()[currentLight].getWhereStopX())
		if(l.getLight(currentLight).getstopXa()>x&&x+16<l.getLight(currentLight).getstopXa())
		{
			if(speed<70)
			speed+=5/10.0;
			droga+=speed/10.0;
			x=(int)droga;
		}//funckja liczaca pretkosc i przemieszczenie
		else
//if(l.getLights()[currentLight].getA())
			if(l.getLight(currentLight).getA())
				x+=2;
			    //funckja liczaca pretkosc i przemieszczenie
		

	}
	private void changePosition(){}
	private void somthink(int pos){
	//position b4 somthink when car is going to stop
		int d=15; 
	//position when car need to stop
		int k=5;
	
	}
}